﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebFormsBinder;
using WebFormModelBinderEntities;
using System.Collections.Generic;

namespace WebFormModelBinder
{
    public partial class _Default : System.Web.UI.Page
    {
        Binder<MyFirstEntity> _binder;

        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);

            _binder = new Binder<MyFirstEntity>();
            _binder.Bind(x => x.Name, txtName);
            _binder.Bind(x => x.Rating, txtRating);
            _binder.Bind(x => x.StartDate, txtStartDate);
            _binder.Bind(x => x.EndDate, txtEndDate);
            _binder.Bind(x => x.IsActive, chkActive);
            _binder.Bind(x => x.IsDeleted, chkDelete);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            MyFirstEntity a = new MyFirstEntity();
            a.Name = "Smith";

            if (!IsPostBack)
                _binder.ToForm(a);


            var jsGenerator = new JSGenerator<MyFirstEntity>(new MyFirstEntityValidator(), _binder, a);
            List<string> js = jsGenerator.GetJavascript();
            
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            MyFirstEntity a = new MyFirstEntity();
            _binder.ToEntity(a);

        }
    }
}
